# encoding: utf-8
"""
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    created by lane.chang on '17/10/2024'
    comment: 毫米波雷达
"""
from fastapi import APIRouter, Request, Body

from config import Config
from project.core.function import json_response
from project.lib.decorator import api_common, exec_duration
from project.micro_service.apollo import Apollo
from project.middleware.radar import Radar


radar_router = APIRouter(prefix='/c', tags=['cariabot.radar'])


@radar_router.get('/radar/user/memories/init', summary='清除记忆')
@api_common(doc_replace=(('{0}', Config.ENV_DOC_FIX),), dev_info=True)
@exec_duration(add_return=True)
async def do_user_memories_init(request: Request, device=None):
    """
    **desc**: 服务记录取消

    **url**: http(s)://{0}.udicaria.com/c/radar/user/memories/init

    **method**: GET

    **return**:json数据结构::

        {
            code: 0(成功)/非0(失败)
            message: 成功返回success, 否则返回error信息
            data:
            exec_time: 接口后端处理时长
        }
    """
    await Apollo.init_radar_user_memories(device.dev_id)

    return json_response()


@radar_router.post('/radar/room/enquire', summary='房间问询')
@api_common(doc_replace=(('{0}', Config.ENV_DOC_FIX),), dev_info=True)
@exec_duration(add_return=True)
async def do_radar_room_enquire(request: Request, user_message: str = Body(..., title='用户话术', embed=True), device=None):
    """
    **desc**: 房间问询

    **url**: http(s)://{0}.udicaria.com/c/radar/room/enquire

    **method**: POST

    **return**:json数据结构::

        {
            code: 0(成功)/非0(失败)
            message: 成功返回success, 否则返回error信息
            data:
            exec_time: 接口后端处理时长
        }
    """
    room_info = await Radar.get_room_list(device.dev_id)
    result = await Apollo.do_radar_room_enquire(device.dev_id, room_info, user_message)

    return json_response(data=result)
